﻿using Microsoft.EntityFrameworkCore;
using RBAC.Api.Demain.ContentManagement;
using RBAC.Api.Demain.Entities;

namespace RBAC.Api.Infaction
{
    public class MyDbContext : DbContext
    {
        private readonly DbContextOptions options;

        public MyDbContext(DbContextOptions options) : base(options)
        {
            this.options = options;
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseMySql("server=8.141.112.218;uid=root;pwd=zpj20040217;database=ContentManagement", new MySqlServerVersion("5.7"));
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity<User>().HasQueryFilter(x=>!x.IsDeleted);
            modelBuilder.Entity<Role>().HasQueryFilter(x => !x.IsDeleted);
            modelBuilder.Entity<Permission>().HasQueryFilter(x => !x.IsDeleted);
            modelBuilder.Entity<UserRole>().HasQueryFilter(x => !x.IsDeleted);
            modelBuilder.Entity<RolePermission>().HasQueryFilter(x => !x.IsDeleted);
            //=======================================================================
            // 内容管理实体软删除过滤器
            modelBuilder.Entity<CarouselChartModel>().HasQueryFilter(x => !x.IsDeleted);
            modelBuilder.Entity<HospitalModel>().HasQueryFilter(x => !x.IsDeleted);
            modelBuilder.Entity<DepartmentModel>().HasQueryFilter(x => !x.IsDeleted);
        }
        #region RBAC表
        /// <summary>
        /// 用户表
        /// </summary>
        public DbSet<User> Users { get; set; }

        /// <summary>
        /// 角色表
        /// </summary>
        public DbSet<Role> Roles { get; set; }

        /// <summary>
        /// 权限表
        /// </summary>
        public DbSet<Permission> Permissions { get; set; }

        /// <summary>
        /// 用户角色关联表
        /// </summary>
        public DbSet<UserRole> UserRoles { get; set; }

        /// <summary>
        /// 角色权限关联表
        /// </summary>
        public DbSet<RolePermission> RolePermissions { get; set; }
        #endregion

        //==============================================================
        #region 内容管理表
        /// <summary>
        /// 轮播图表
        /// </summary>
        public DbSet<CarouselChartModel> CarouselCharts { get; set; }
        /// <summary>
        /// 科室表
        /// </summary>
        public DbSet<DepartmentModel> Departments { get; set; }
        /// <summary>
        /// 医院表
        /// </summary>
        public DbSet<HospitalModel> Hospitals { get; set; }
        #endregion
       
    }
}
